#Include <File.au3>
#Include <ScreenCapture.au3>
#include <process.au3>
#Include <GuiTreeView.au3>
#Include <String.au3>
#include <Array.au3>

Global $GHOST_FOLDER_PATH = StringReplace(@ScriptDir, 'AutomationTest\Scripts', 'Ghost\')

Global $LOCALIZE_FOLDER_PATH = StringReplace(@ScriptDir, 'Scripts', 'Localize\')

Global $SAMPLE_FOLDER_PATH = StringReplace(@ScriptDir, 'Scripts', 'Sample\')

Global $PERFORM_RESULT_FOLDER_PATH = StringReplace(@ScriptDir, 'Scripts', 'Localize\Result\Perform Result\') & GetOSLanguage() & '\'

Global $PERFORM_RESULT_FOLDER_PATH_ = StringReplace(@ScriptDir, 'Scripts', 'Localize\Result\Perform Result\')

Global $CORRECT_RESULT_FOLDER_PATH = StringReplace(@ScriptDir, 'Scripts', 'Localize\Result\Correct Result\') & GetOSLanguage() & '\'

Global $CORRECT_RESULT_FOLDER_PATH_ = StringReplace(@ScriptDir, 'Scripts', 'Localize\Result\Correct Result\')

Global $LOG_FODLER_PATH = StringReplace(@ScriptDir, 'Scripts', 'Localize\Result\Log\')

Global $MY_PAGEMANAGER_FODLER_PATH = @MyDocumentsDir & "\My PageManager\"

Global $LOG_FILE_PATH = $LOG_FODLER_PATH & GetOSLanguage() & '.log'

Global $INI_PATH = GetINIPath()

If $INI_PATH == False Then
	
	MsgBox('','','No ini file has been found!')
	
	Exit
EndIf

Global Const $PMFolder = @MyDocumentsDir & "\My PageManager\"   ;My PageManager folder path.

Global $INI_SECTION_NAME_INSTALLER = 'Installer'

Global $INSTALLER_SELF_EXTRACT_TIME = Number(IniRead($INI_PATH, $INI_SECTION_NAME_INSTALLER, 'InstallerSelfExtractTime', '10')) * 1000

Global $COPY_FILE_TIME = Number(IniRead($INI_PATH, $INI_SECTION_NAME_INSTALLER, 'CopyFileTime', '10')) * 1000

Global $SN = IniRead($INI_PATH, $INI_SECTION_NAME_INSTALLER, 'SN', '')

Global $Dll1 = @ScriptDir & "\Dll\Ism.dll"

Global $Dll2 = @ScriptDir & "\Dll\ImageOperate.dll"

Global $Dll3 = @ScriptDir & "\Dll\FioAll32.dll"

Global $Dll4 = @ScriptDir & "\Dll\Fiotif32.dll"

Global $SETUP_EXE_PATH = GetSetpupEXEPath()

; --------------------------------------------------------------------------------------------------------------

Func CompareImage ($file1,$file2,$Pixels=5)
	
		Local $dllb,$dllc,$dlla,$dll,$result
		
		$dllb = DllOpen ($Dll3)
		
		$dllc = DllOpen ($Dll4)
		
		$dlla = DllOpen ($Dll1)
		
		$dll = DllOpen ($Dll2)
		
		$result = DllCall($dll, "int","Auto_CompareFile", "str",$file1, "str",$file2,"int",$Pixels)
		
		If Not @error Then
			
			If $result[0] = 1 Then 
				
				Return 1
				
			Else
				
				Return @error
				
			EndIf
			
		EndIf
		
		DllClose($dll)
		
		DllClose($dlla)
		
		DllClose($dllb)
		
		DllClose($dllc)
EndFunc
	
Func ClickPageViewButton($hPMHandle)
	
	ControlClick($hPMHandle, '', 1034)    ;page view button
	
EndFunc	

Func ClickThumbnailButton($hPMHandle)
	
	ControlClick($hPMHandle, '', 1026)    ;thumbnial view button
	
EndFunc	

Func CompareFile ($file1,$file2)
	If FileExists($file1) And FileExists($file2) And (FileGetSize ($file1) > 100) And (FileGetSize ($file2) > 100) Then
		
		Local $var = StringRight ($file1, 4)
		
		If $var = ".tif" Then
			
			Return CompareImage ($file1,$file2)
			
		Else	
			Local $file_A,$chars_A,$file_B,$chars_B
			
			$file_A = FileOpen ($file1, 16)
			
			$chars_A = FileRead ($file_A)
			
			$file_B = FileOpen ($file2, 16)
			
			$chars_B = FileRead ($file_B)
			
			FileClose ($file_A)
			
			FileClose ($file_B)
			
			If FileExists($file1) Then
				
				If $chars_A = $chars_B Then
					
					Return 1
				Else
					
					Return @error
					
				EndIf
				
			Else
				
				Return @error
				
			EndIf
		EndIf	
		
	EndIf
EndFunc

Func SelectProgrameFolderDialogTest() 
	
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "INSTALL_Select Programe Folder Dialog.jpg", WinGetHandle(""))	
		
	;For PM there are selsect sharepoint dialog
	If ControlGetHandle('','', 401) <> '' Then
		
		ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "INSTALL_Select SharePoint Dialog.jpg", WinGetHandle(""))	
		
		CliclkNextButton()   ;Go to next dialog.
		
	EndIf
EndFunc	

Func IsHasNextStep()
	If CheckIsHasNextStep() = False Then   ;No next step, it's copying file.
		
		WaitMoveFile($COPY_FILE_TIME)  
		
		WinActivate("[CLASS:#32770]")
		
		Sleep(1000)
		
		ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_Finish Dialog.jpg', WinGetHandle(''))
		
		FinishedInstall()
		
		Return 'NO'
		
	EndIf	
	Return 'YES'
EndFunc

Func SelectDestnitionDialogTest() 
	
	WinActivate("[CLASS:#32770]")
	
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "INSTALL_Select Target Path Dialog.jpg", WinGetHandle(""))	
	
EndFunc	

Func SNDialogTest() 
	
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "INSTALL_SN Dialog.jpg", WinGetHandle(""))
	
	WinActivate("[CLASS:#32770]")
	
	If ControlGetHandle('','', 303) <> '' Then
		
		ControlFocus('','', 301)   ;Make the focus in user name edit box.
		
		Sleep (500)
		
		ControlSetText ("", "", 301, 'userName')   ;Input user name. 
		
		Sleep (500)
		
		ControlFocus('','', 302)   ;Make the focus in user company edit box.
		
		Sleep (500)
		
		ControlSetText ("", "", 302, 'cimpany')   ;Input company. 
		
		Sleep (500)
		
		ControlFocus('','', 303)   ;Make the focus in user SN edit box.
		
		Sleep (500)
		
		ControlSetText ("", "", 303, 'wrongSN')   ;Input wrong SN. 
		
		Sleep (500)	
		
		CliclkNextButton()
		
		Sleep(1000)
		
		ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "INSTALL_Wrong SN Dialog.jpg", WinGetHandle(""))
		
		Send("{ENTER}")   ;Close alert messgae of wrong SN.
		
		Sleep(1000)
		
		ControlFocus('','', 303)   ;Make the focus in user SN edit box.
		
		Sleep (500)
		
		ControlSetText ("", "", 303, $SN)   ;Input correct SN. 
		
		Sleep (500)
		
	EndIf	
EndFunc	

Func LicenseDialogTest() 
	
	WinActivate("[CLASS:#32770]")
	
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "INSTALL_License Dialog.jpg", WinGetHandle(""))

	ControlFocus('','', 301)   ;Make the focus in licensen edit box.
	
	Sleep(800)
	
	For $i = 1 to 25
		
		Send ("{PGDN}")
		
		Sleep (200)
		
	Next
	
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "INSTALL_License Agreement.jpg", ControlGetHandle(WinGetHandle(''), '', 301))
	
	Sleep(1000)
	
EndFunc	

Func DetermineCurrentDialog()   
	
	Local $hLicenseEidt = ControlGetHandle("", "", 301)   ;License dilaog.
	
	Local $hSNEidt1 = ControlGetHandle("", "", 303)   ;SN dilaog.
	
	Local $hSNEidt2 = ControlGetHandle("", "", 301)   ;SN dilaog.
	
	Local $hSelectDestnition = ControlGetHandle("", "", 196)   ;Select detinition dilaog.
	
	Local $hSelectProgramefolder = ControlGetHandle("", "", 401)   ;Select programe folder of start menu.
	
	If $hSNEidt1 <> "" And $hSNEidt2 <> "" Then   ;This SN dialog.
		
		Return 'SNDialog'
		
	EndIf		
	
	If $hLicenseEidt <> "" Then   ;This license dialog.
		
		Return 'LicenseDialog'
		
	EndIf		
	
	If $hSelectDestnition <> "" Then   ;This select install destnition dialog.
		
		Return 'SelectDestnition'
		
	EndIf	
	
	If $hSelectProgramefolder <> "" Then   ;This select programe folder of start menu dialog.
		
		Return 'SelectProgramefolder'
		
	EndIf		
EndFunc	

	;Click finish button.
Func FinishedInstall()
	
	Sleep(130000)
	
	WinActivate("[CLASS:#32770]")
	
	;Unselect restart option when finished copy file.
	Local $hRestart = ControlGetHandle('', '', 503)
	
	If $hRestart <> "" Then
		
		ControlClick("", "", 503)   ;Unselect restart option.
		
		Sleep(500)
		
	EndIf	

	If ControlGetHandle('', '', 12128) <> '' Then 
		
		ControlClick("", "", 1)   ; Finish install.
		
		Sleep(5000)	
		
	Else	
		ControlClick("", "", 1)   ; Finish install.
		
		Sleep(5000)	
		
	EndIf
	
	;For Digitak Signage.close install quitck time 7 dialog.
	If ControlGetHandle('', '', 'Button1') <> '' Then 
		Send('{ENTER}')
		Sleep(5000)	
	EndIf
EndFunc	

Func GetInstalledAPPath()	
		If WinExists('CRC') Then
			WinActivate('CRC')
			Sleep(300)
			ControlClick('CRC', '', 'Button3')   ;Click Ignore button
			Sleep(1000)
		EndIf
		
		;For Digitial
		If  ControlGetHandle('', '', 'TNewComboBox1') <> '' Then
			Send('{ESC}')
			Sleep(1500)
			Send('{ESC}')
			Sleep(1500)
		EndIf	
	
	Dim $Uninstall,$32REG, $64REG,$REG
	$32REG = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
	$64REG = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
	If @OSArch = 'X64' Then
		$REG = $64REG
	Else
		$REG = $32REG
	EndIf	
	For $t = 1 To 900
		For $i = 1 to 150
			Local $Key = RegEnumKey ($REG, $i)
			For $c = 1 to 100   
				If  RegRead ($REG & "\" & $Key, "Publisher") = "Newsoft Technology Corporation" Or RegRead ($REG & "\" & $Key, "Publisher") = "NewSoft" Then
					$Uninstall = RegRead ($REG & "\" & $Key, "InstallLocation")
					If StringLen($Uninstall) > 3 Then
						Return $Uninstall
						ExitLoop
					EndIf
				EndIf
			Next
		Next	
	Sleep(1000)
	Next
	Return ""
EndFunc	

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func CloseRubbishWindow()
	WinClose('[CLASS:#32770]', 'Tree View')
	WinClose('[CLASS:#32770]', 'FolderView')
EndFunc

Func ActivateInstallerWindow()
	$var = WinList ()
	If @error Then Return False
	For $i = 1 to $var[0][0]
		If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
			If StringInStr($var[$i][0], 'InstallShield') Then
				Return $var[$i][0]
			EndIf
		EndIf	
	Next
	Return False
EndFunc

Func CheckScanButtonSettings($hPMHandle)	
	Send ("!t")
	Sleep (1000)
	Send ("b")
	Sleep (35000)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "1.1.3_Scan Button Settings 1.jpg", WinGetHandle(""))
	Send('{DOWN}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "1.1.3_Scan Button Settings 2.jpg", WinGetHandle(""))
	Send('{DOWN}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "1.1.3_Scan Button Settings 3.jpg", WinGetHandle(""))
	Send('{DOWN}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "1.1.3_Scan Button Settings 4.jpg", WinGetHandle(""))
	Send('{DOWN}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "1.1.3_Scan Button Settings 5.jpg", WinGetHandle(""))	
	Send('{DOWN}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "1.1.3_Scan Button Settings 6.jpg", WinGetHandle(""))	
	Sleep(500)
	Send ("{ESC}")
	Sleep(1000)
EndFunc

Func CheckScanSettings($hPMHandle)
	Send ("!f")
	Sleep (1000)
	Send ("A")
	Sleep (35000)
	ControlFocus('','',1)
	Sleep (1000)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Scan Settings.jpg", WinGetHandle(""))
	Sleep(500)
	Send ("{ESC}")	
	Sleep(1000)
EndFunc

Func CheckMenu($hPMHandle)
	Send ("!f")
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Menu_File Menu.jpg", WinGetHandle("[CLASS:#32768]"))
	Send('{RIGHT}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Menu_Edit Menu.jpg", WinGetHandle("[CLASS:#32768]"))
	Send('{RIGHT}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Menu_View Menu.jpg", WinGetHandle("[CLASS:#32768]"))
	Send('{RIGHT}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Menu_Tools Menu.jpg", WinGetHandle("[CLASS:#32768]"))
	Send('{RIGHT}')
	Sleep(1500)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Menu_Help Menu.jpg", WinGetHandle("[CLASS:#32768]"))
	Send ("{ESC}")
	Sleep(1000)
EndFunc

Func UnistallerEXEPath()
	Dim $Uninstall,$32REG, $64REG,$REG
	$32REG = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
	$64REG = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
	If @OSArch = 'X64' Then
		$REG = $64REG
	Else
		$REG = $32REG
	EndIf	
	For $t = 1 To 900
		For $i = 1 to 150
			Local $Key = RegEnumKey ($REG, $i)
			For $c = 1 to 100   
				If  RegRead ($REG & "\" & $Key, "Publisher") = "Newsoft Technology Corporation" Or RegRead ($REG & "\" & $Key, "Publisher") = "NewSoft" Then
					$Uninstall = RegRead ($REG & "\" & $Key, "UninstallString")
					If StringLen($Uninstall) > 3 Then
						Return $Uninstall
						ExitLoop
					EndIf
				EndIf
			Next
		Next	
	Next
	Return ""
EndFunc

Func CheckAbout($hPMHandle)
	WinActivate($hPMHandle)
	Send ("!h")
	Sleep (500)
	Send ("{up}")  
	Sleep (500)
	Send ("{ENTER}")
	Sleep (1000)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "About.jpg", WinGetHandle(""))
	Send ("{ENTER}")
	Sleep (1000)
EndFunc

Func CheckHelpCHM($hPMHandle)
	WinActivate($hPMHandle)
	Send ("!h")
	Sleep (500)
	Send ("{DOWN}")  
	Sleep (500)
	Send ("{ENTER}")
	Sleep (1300)
	WinActivate ("")
	WinSetState ("", "",@SW_MAXIMIZE)
	MouseClick ("left", 716, 143)
	Send ("{PGDN}")
	Sleep (1300)
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "1.1.23_Help CHM.jpg", WinGetHandle(""))
	ProcessClose('hh.exe')
	Sleep (1000)
EndFunc

Func LaunchAP($sAPEXEPath)
	Local $Titile,$size
	Local $avArray[100]
	FileDelete(@MyDocumentsDir & "\My PageManager\*.*")
	Sleep(2000)
	DirRemove(@MyDocumentsDir & "\My PageManager\", 1)
	Sleep(2000)
	For $i = 0 to 4
		If FileExists(@MyDocumentsDir & "\My PageManager\") Then DirRemove(@MyDocumentsDir & "\My PageManager\", 1)
	Next		
	DirCreate(@MyDocumentsDir & "\My PageManager\")
	Sleep(2000)
	Local $PIDa = Run($sAPEXEPath, "", @SW_MAXIMIZE)
	Sleep(10000)
	If WinExists("[CLASS:#32770]", "Try") Then
		WinActivate("[CLASS:#32770]", "Try")
		ControlClick("[CLASS:#32770]", "Try", 1000)
		Sleep(10000)
	EndIf
	
	If ControlGetHandle(WinGetHandle("Presto! PageManager 9 Professional"), "", "Static10") <> "" Then
		
		WinActivate('Presto! PageManager 9 Professional')
		
		ControlClick('Presto! PageManager 9 Professional', '', 'Button1')
		
		Sleep(10000)
		
	EndIf

	If WinExists("Scan Central") Then
		WinActivate("Scan Central")
		Sleep(300)
		WinClose("Scan Central")
	EndIf
	If ControlGetHandle(WinGetHandle(''), '', 1127) <> '' Then
		Send("{ENTER}")
		Sleep(10000)
	EndIf
	Local $Var = WinList()
	For $i = 1 to $Var[0][0]
		If $Var[$i][0] <> "" And IsVisible($var[$i][1]) Then
			$avArray[$i] = WinGetProcess($Var[$i][0])   ; Get all visible title PID.
			If $PIDa = $avArray[$i] Then
				$Titile = $Var[$i][0]   ; Get PM title.
				$size = WinGetPos($Titile)   ;Get PM postion and size.
				MouseClick('left',($size[0] + $size[2] / 1.135), ($size[1] + $size[3] / 32.19))
				Sleep (5000)
				While ProcessExists("iexplore.exe")
					ProcessClose ("iexplore.exe")
				WEnd
				Return WinGetHandle($Titile)
			EndIf
		EndIf
	Next
	Return ""
EndFunc

Func ClosePM($hHandle)
	WinActivate($hHandle)
	If ProcessExists ("PageViewer.exe") Then
		If ProcessExists ("PageViewer.exe") Then
			ProcessClose ( "PageViewer.exe")
			Sleep (500)
		EndIf
	EndIf	
	
	If ProcessExists ("Prestopm.exe") Then
		WinActivate($hHandle)   ;Activate the PM window.
		Sleep(500)
		Send ("!f")
		Sleep (500)
		Send ("E")   ; Close PM.
		Sleep (1000)
		If ProcessExists ("Prestopm.exe") Then
			ProcessClose ( "Prestopm.exe")
			Sleep (1000)
		EndIf
	EndIf	
	
	If ProcessExists('Pmsb.exe') Then
		ProcessClose('Pmsb.exe')
	EndIf
	
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd
	
EndFunc

Func ClosePM_()
	
	If ProcessExists ("PageViewer.exe") Then
		If ProcessExists ("PageViewer.exe") Then
			ProcessClose ( "PageViewer.exe")
			Sleep (500)
		EndIf
	EndIf	
	
	If ProcessExists ("Prestopm.exe") Then
		ProcessClose ( "Prestopm.exe")
		Sleep (1000)
	EndIf
	
	If ProcessExists('Pmsb.exe') Then
		ProcessClose('Pmsb.exe')
	EndIf
	
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd
	
EndFunc
 
Func CheckStartMenu()
	$thePath = 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\'
	$FileList = _FileListToArray($thePath, '*' , 2)
	If @error Then Return False
	For $i = 1 to $FileList[0]
		If StringInStr($FileList[$i], 'Presto') Then
			$folder_ = $thePath & $FileList[$i]
			ShellExecute($folder_)
			Sleep(1500)
			ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "StartMenu.jpg", ControlGetHandle(WinGetHandle($FileList[$i]), '', 'DirectUIHWND3'))
			WinClose($FileList[$i])
			Return
		EndIf
	Next
EndFunc

Func CheckReadMe()
	$localReadmePath = GetPMExePath()
	$localReadmePath = StringReplace($localReadmePath, 'prestopm.exe', 'LocalReadMe.exe')
	Run($localReadmePath)
	Sleep (1000)
	WinSetState(WinGetHandle(''), '', @SW_MAXIMIZE)
	Sleep(500)
	For $i = 1 to 10
		Send ("{PGDN}")
		Sleep(300)
	Next
	If ProcessExists('notepad++.exe') Then
		ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Readme.jpg", ControlGetHandle(WinGetHandle(''), '', 'Scintilla1'))
		Sleep(500)
		ProcessClose('notepad++.exe')
	EndIf
	If ProcessExists('notepad.exe') Then
		ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "Readme.jpg", ControlGetHandle(WinGetHandle(''), '', 'Edit1'))
		Sleep(500)
		ProcessClose('notepad.exe')
	EndIf
	Sleep (1000)
EndFunc

Func GetPMExePath()	
	Dim $Uninstall,$32REG, $64REG,$REG
	$32REG = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
	$64REG = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
	If @OSArch = 'X64' Then
		$REG = $64REG
	Else
		$REG = $32REG
	EndIf	
	For $t = 1 To 900
		For $i = 1 to 150
			Local $Key = RegEnumKey ($REG, $i)
			For $c = 1 to 100   
				If  RegRead ($REG & "\" & $Key, "Publisher") = "Newsoft Technology Corporation" Or RegRead ($REG & "\" & $Key, "Publisher") = "NewSoft" Then
					$Uninstall = RegRead ($REG & "\" & $Key, "DisplayIcon")
					If StringLen($Uninstall) > 3 Then
						Return $Uninstall
						ExitLoop
					EndIf
				EndIf
			Next
		Next	
	Next
	Return ""
EndFunc	

Func WaitMoveFile($iCopyFileTime)
	Local $count = 0
	While True
		Sleep(25000)
		If WinExists('CRC') Then
			WinActivate('CRC')
			Sleep(300)
			ControlClick('CRC', '', 'Button3')   ;Click Ignore button
			Sleep(1000)
		EndIf
		
		;For Digitial
		If  ControlGetHandle('', '', 'TNewComboBox1') <> '' Then
			Send('{ESC}')
			Sleep(1500)
			Send('{ESC}')
			Sleep(1500)
		EndIf

		If GetInstalledAPPath() <> "" Then   ;Wait copy files.	
			Local $iSize1 = FileGetSize(GetInstalledAPPath())
			Sleep(10000)			
			Local $iSize2 = FileGetSize(GetInstalledAPPath())				
			Sleep(10000)			
			If $iSize1 = $iSize1 Then						
				Sleep(60000)			
				Return True	
			EndIf	
		Else
			Sleep($iCopyFileTime)
		EndIf	
		
		$count = $count + 1
		
		If $count == 30 Then Return True
	WEnd	
EndFunc	

Func CheckIsHasNextStep()
	Sleep(1500)
	Local $hNextButton_1 = ControlGetHandle('', '', 1)
	Local $hNextButton_2 = ControlGetHandle('', '', 6)
	If $hNextButton_1 <> "" Or $hNextButton_2 <> "" Then   ;has next button.
		WinActivate("[CLASS:#32770]")
		Return True
	Else
		WinActivate("[CLASS:#32770]")
		Return False
	EndIf
EndFunc

Func CliclkNextButton()
	Local $hNextButton = ControlGetHandle('', '', 1)    ;The next button ID is 1.
	If $hNextButton <> "" Then  
		ControlClick('', '', 1)
		Sleep(1300)
		Return True
	Else
		$hNextButton = ControlGetHandle('', '', 6 )
		If $hNextButton <> '' Then
			ControlClick('', '', 6)    ;The next button ID is 6.
			Sleep(1300)
			WinActivate("[CLASS:#32770]")
			Return True
		EndIf
	EndIf
		WinActivate("[CLASS:#32770]")
		Return False
EndFunc

Func ClickCancelButton()
	Local $hCancelButton = ControlGetHandle('', '', 9)   ;The cancel button ID is 9.
	If $hCancelButton <> "" Then   
		ControlClick('', '', 9)   ;Click cancel button. 
		Sleep(1000)
		Return True
	Else
		WriteLog('ClickCancelButton() --- Click cancel button faild!')
		Return False
	EndIf	
EndFunc	

Func WriteLog($sLogMsg,$iFlag = -1)
	Local $sDateNow, $sTimeNow, $sMsg, $iWriteFile, $hOpenFile, $iOpenMode = 1 
    $sMsg = @CRLF & $sLogMsg 
	If $iFlag <> -1 Then
		$sMsg &= @CRLF & FileRead ($LOG_FILE_PATH)
		$iOpenMode = 2
	EndIf
	$hOpenFile = FileOpen ($LOG_FILE_PATH, 129)
	If $hOpenFile = -1 Then Return SetError(1, 0, 0)
	$iWriteFile = FileWriteLine ($hOpenFile, $sMsg)
	If $iWriteFile = -1 Then Return SetError (2, 0, 0)
	Return FileClose ($hOpenFile)
EndFunc 

Func WriteLog_($logPath, $sLogMsg,$iFlag = -1)
	Local $sDateNow, $sTimeNow, $sMsg, $iWriteFile, $hOpenFile, $iOpenMode = 1 
    $sMsg = @CRLF & $sLogMsg 
	If $iFlag <> -1 Then
		$sMsg &= @CRLF & FileRead ($logPath)
		$iOpenMode = 2
	EndIf
	$hOpenFile = FileOpen ($logPath, 129)
	If $hOpenFile = -1 Then Return SetError(1, 0, 0)
	$iWriteFile = FileWriteLine ($hOpenFile, $sMsg)
	If $iWriteFile = -1 Then Return SetError (2, 0, 0)
	Return FileClose ($hOpenFile)
EndFunc 

Func ClickMouseToSetfocus()	
	Local $pos = WinGetPos('')   ;Get current dialog position.
	Mouseclick('left',($pos[0] + $pos[2] / 1.1), ($pos[1] + $pos[3] / 8.1))   ;clicl mouse left button to make the focus on current dialog.
	Sleep(400)
EndFunc

Func BeforeWelcomeDialog()
	;For PM9 select language in combobox UI.
	Local $hSelectlanguage = ControlGetHandle("", "", "ComboBox1")
	If $hSelectlanguage <> "" Then   ;This is the select language dialog.
		ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_BeforeWelcomeDialog.jpg', WinGetHandle(''))
		Send ("{ENTER}")   ;Go to the welcome dialog.
		Sleep(10000)
	EndIf
EndFunc

Func ScreenCaprureWindow($sPerformResultPath,$sCaptureImage,$WndTitle)
	If WinExists($WndTitle) And $WndTitle <> "" Then
		Local $iPos = GetWindowPostion($WndTitle)
		If @error Then Return False
		_ScreenCapture_CaptureWnd($sPerformResultPath & $sCaptureImage, WinGetHandle($WndTitle), 3, 3 ,$iPos[2] - 3,$iPos[3] - 3, False)		
	EndIf
EndFunc

Func GetWindowPostion($WndTitle)
	If WinExists($WndTitle) And $WndTitle <> "" Then
		Local $size = WinGetPos($WndTitle)
		If @error Then Return False
		Local $xy[4] = [$size[0], $size[1], $size[2], $size[3]]
		Return $xy
	EndIf	
EndFunc

Func GetSetpupEXEPath()
	$path1 = IniRead ($INI_PATH, $INI_SECTION_NAME_INSTALLER, 'InstalelrEXEPath', "Error" )
	$path2 = StringReplace(@ScriptDir, 'Scripts', 'SPG\') & $path1
	If Not FileExists($path2) Then
		MsgBox('','','setup.exe does not exist!')
		Exit
	Else
		Return $path2
	EndIf
EndFunc
Func GetINIPath()
	$FileList=_FileListToArray($LOCALIZE_FOLDER_PATH)
	If @error Or $FileList == 0 Then Return False
	For $i = 1 to $FileList[0]
		If StringInStr($FileList[$i], '.ini') Or StringInStr($FileList[$i], '.INI') Then
			Return $LOCALIZE_FOLDER_PATH & $FileList[$i]
		EndIf
	Next
	Return False
EndFunc

Func CreatePath($path)
	DirCreate($path)
	Sleep(500)
	If FileExists($path) Then
	Else
		DirCreate($path)
		Sleep(500)
	EndIf
EndFunc

Func GetOSLanguage()
	$sLan = IniRead('C:\Program Files\OS_Language.ini', 'Language', 'OS_Language', '')
	If $sLan == 'PT_PT' Then Return 'PT_PT'	
	If $sLan == 'EN_UK' Then Return 'EN_UK'		
Select
    Case StringInStr("0412", @OSLang)
        Return "Korean"
		
    Case StringInStr("041b", @OSLang)
        Return "Slovak"	
		
    Case StringInStr("0411", @OSLang)
        Return "Japanese"
		
    Case StringInStr("0421", @OSLang)
        Return "Indonesian"
		
    Case StringInStr("040f", @OSLang)
        Return "Icelandic"
		
    Case StringInStr("0439", @OSLang)
        Return "Hindi"
		
    Case StringInStr("040d", @OSLang)
        Return "Hebrew"
		
    Case StringInStr("408", @OSLang)
        Return "Greek"
		
    Case StringInStr("0437", @OSLang)
        Return "Georgian"
		
    Case StringInStr("040b", @OSLang)
        Return "Finnish"
		
    Case StringInStr("0429", @OSLang)
        Return "Farsi"
		
    Case StringInStr("0438", @OSLang)
        Return "Faeroese"
		
    Case StringInStr("0425", @OSLang)
        Return "Estonian"	
		
    Case StringInStr("0406", @OSLang)
        Return "Danish"	

    Case StringInStr("0405", @OSLang)
        Return "Czech"	
		
    Case StringInStr("041a", @OSLang)
        Return "Croatian"	

    Case StringInStr("1404", @OSLang)
        Return "Chinese_Macau"
		
    Case StringInStr("1004", @OSLang)
        Return "Chinese_Singapore"
		
    Case StringInStr("0c04", @OSLang)
        Return "Chinese_Hong_Kong"
		
    Case StringInStr("0804", @OSLang)
        Return "Chinese_PRC"
		
    Case StringInStr("0404", @OSLang)
        Return "Chinese_Taiwan"
		
    Case StringInStr("0403", @OSLang)
        Return "Catalan"
		
    Case StringInStr("0402", @OSLang)
        Return "Bulgarian"
		
    Case StringInStr("0423", @OSLang)
        Return "Belarusian"
		
    Case StringInStr("042d", @OSLang)
        Return "Basque"	
	
    Case StringInStr("0436", @OSLang)
        Return "Afrikaans"	
		
    Case StringInStr("041c", @OSLang)
        Return "Albanian"	
		
    Case StringInStr("042b", @OSLang)
        Return "Armenian"	
		
    Case StringInStr("042c 082c", @OSLang)
        Return "Azeri"	
		
    Case StringInStr("0401 0801 0c01 1001 1401 1801 1c01 2001 2401 2801 2c01 3001 3401 3801 3c01 4001" , @OSLang)
        Return "Arabic"
		
    Case StringInStr("0413 0813", @OSLang)
        Return "Dutch"

    Case StringInStr("0409 0809 0c09 1009 1409 1809 1c09 2009 2409 2809 2c09 3009 3409", @OSLang)
        Return "English"

    Case StringInStr("040c 080c 0c0c 100c 140c 180c", @OSLang)
        Return "French"

    Case StringInStr("0407 0807 0c07 1007 1407", @OSLang)
        Return "German"

    Case StringInStr("0410 0810", @OSLang)
        Return "Italian"

    Case StringInStr("0414 0814", @OSLang)
        Return "Norwegian"

    Case StringInStr("0415", @OSLang)
        Return "Polish"

    Case StringInStr("0416 0816", @OSLang)
        Return "Portuguese"

    Case StringInStr("040a 080a 0c0a 100a 140a 180a 1c0a 200a 240a 280a 2c0a 300a 340a 380a 3c0a 400a 440a 480a 4c0a 500a", @OSLang)
        Return "Spanish"

    Case StringInStr("041d 081d", @OSLang)
        Return "Swedish"

    Case StringInStr("0418", @OSLang)
        Return "Romanian"

    Case StringInStr("0424", @OSLang)
        Return "Slovenian"
		
    Case StringInStr("0419", @OSLang)
        Return "Russian"

    Case StringInStr("0441", @OSLang)
        Return "Swahili"

    Case StringInStr("041f", @OSLang)
        Return "Turkish"
		
    Case StringInStr("040e", @OSLang)
        Return "Hungarian"
EndSelect
	Return 'Error'
EndFunc

Func PMSpeedEXE_Path()
	Return StringReplace(GetPMExePath(), 'prestopm.exe', 'PMSpeed.exe')
	Dim $FileList,$FileList1,$Path
	$FileList = _FileListToArray ("C:\Program Files\NewSoft", "*", 2)
	If @error Then
		$FileList = _FileListToArray ("C:\Program Files (x86)\NewSoft", "*", 2)
			For $i =1 to $FileList[0]
				$FileList1 = _FileListToArray ("C:\Program Files (x86)\NewSoft" & "\" & $FileList[$i], "PMSpeed.exe", 1)
				If $i = $FileList[0] Then
					If @error Then 
						MsgBox("", "", "PMSpeed.exe has not found!")	
					Else		
						$Path = "C:\Program Files (x86)\NewSoft\" & $FileList[$i] & "\" & $FileList1[$i]
						Return $Path
					EndIf
				EndIf	
			Next
	Else	
			For $i =1 to $FileList[0]
				$FileList1 = _FileListToArray ("C:\Program Files\NewSoft" & "\" & $FileList[$i], "PMSpeed.exe", 1)
				If $i = $FileList[0] Then
					If @error Then 
						MsgBox("", "", "PMSpeed.exe has not found!")
					Else
						$Path = "C:\Program Files\NewSoft\" & $FileList[$i] & "\" & $FileList1[$i]
						Return $Path
					EndIf
				EndIf
			Next
	EndIf
EndFunc

Func GetThumbnailHandle($hPMHandle)
	$h = ControlGetHandle($hPMHandle, '', 'SysListView323')
	If $h == 0 Then $h = ControlGetHandle($hPMHandle, '', 'SysListView321')
	If $h == 0 Then $h = ControlGetHandle($hPMHandle, '', 'SysListView322')
	Return $h
EndFunc

Func SetSaveAsFormat($Format)
	ControlClick("[CLASS:#32770]", "FolderView", 1136)
	Sleep(500)
	Switch $Format   
	Case "BMP(*.BMP)"

	Case "JPEG(*.JPG)"
		Send("j")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PaintBrush(*.PCX)"
		Send("p")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-uncompressed(*.TIF)"
		Send("t")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-packbits(*.TIF)"
		For $i = 0 to 1
			Send("t")
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-G3 compression(*.TIF)"
		For $i = 0 to 2
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-G4 compression(*.TIF)"
		For $i = 0 to 3
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-multiple page(*.TIF)"
		For $i = 0 to 4
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "JPEG(*.JPG)"
		Send("j")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PICT(*.PCT)"
		Send("p")
		Send("p")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Targa(*.TGA)"
		For $i = 0 to 5
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Targa-rle(*.TGA)"
		For $i = 0 to 6
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PNG(*.PNG)"
		For $i = 0 to 2
			Send("p")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Photoshop(*.PSD)"
		For $i = 0 to 3
			Send("p")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "GIF(*.GIF)"
		Send("g")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Text(*.TXT)"
		For $i = 0 to 7
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Rich Text Format(*.RTF)"
		Send("r")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "HTML(*.HTM)"
		Send("h")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	EndSwitch
EndFunc

Func SetSaveAsFileName($sName)
	Sleep(3000)
	ControlFocus('', "", 1152)
	Sleep(1000)
	For $i = 0 To 20
		Send('{DEL}')
	Next
	For $i = 0 To 20
		Send('{BS}')
	Next	
	Sleep(1000)
	ControlSend('', "", 1152, $sName)
	Sleep(5000)
	ControlClick('', "", "Button2")
	Sleep(5000)
	If WinExists("OCR") Then
		WinWaitClose("OCR", "", 30)
		Sleep(2000)
	EndIf
EndFunc

Func InitializeStatus()   
	For $i = 0 To 5
		Send('{ESC}')
		Sleep(200)
	Next
	For $i = 0 To 5
		WinActivate('[CLASS:#32770]', 'FolderView')
		Send('{ESC}')
		Sleep(200)
	Next
	For $i = 0 To 5
		WinActivate('[CLASS:#32770]', 'Tree View')
		Send('{ESC}')
		Sleep(200)
	Next	
	For $i = 0 To 5
		WinActivate('[CLASS:#32770]', '')
		Send('{ESC}')
		Sleep(200)
	Next	
	For $i = 0 To 5
		WinActivate(WinGetHandle(''), '')
		Send('{ESC}')
		Sleep(200)
	Next		
	FileRecycleEmpty()
	If ProcessExists('Pmsb.exe') Then
		ProcessClose('Pmsb.exe')
	EndIf
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd
	While ProcessExists('NetGroup.exe')
		ProcessClose('NetGroup.exe')
	WEnd
	While ProcessExists('Scan Central.exe')
		ProcessClose('Scan Central.exe')
	WEnd	
	While ProcessExists('PageViewer.exe')
		ProcessClose('PageViewer.exe')
	WEnd
	If FileExists("C:\MSOCache") Then
		DirRemove("C:\MSOCache", 1)
		Sleep(2000)
	EndIf
	While ProcessExists('hh.exe')
		ProcessClose('hh.exe')
	WEnd
	WinKill ( "[CLASS:Photo_Lightweight_Viewer]" )
	RefreshShellTrayToolbar() 
	Local $FileList=_FileListToArray(@MyDocumentsDir)
	If @Error Then Return
	For $i = 1 to $FileList[0]
		If StringInStr($FileList[$i], 'My PageManager') Or StringInStr($FileList[$i], 'desktop.ini') Or StringInStr($FileList[$i], 'My Music') Or StringInStr($FileList[$i], 'My Pictures') Or StringInStr($FileList[$i], 'My Videos') Then
		Else
			FileDelete(@MyDocumentsDir & '\' & $FileList[$i])
			DirRemove(@MyDocumentsDir & '\' & $FileList[$i], 1)
		EndIf
	Next
	If WinExists("[CLASS:#32770]", "&Yes") Then
		WinActivate("[CLASS:#32770]", "&Yes")
		Sleep(300)
		ControlClick("[CLASS:#32770]", "&Yes", 'Button2')
		Send('{ESC}')
	EndIf
	If WinExists("[CLASS:#32770]", "&Save") Then
		WinActivate("[CLASS:#32770]", "&Save")
		Sleep(300)
		ControlClick("[CLASS:#32770]", "&Save", 'Button1')
		Send('{ESC}')
	EndIf
	If WinExists("[CLASS:#32770]", "OK") Then
		WinActivate("[CLASS:#32770]", "OK")
		Sleep(300)
		ControlClick("[CLASS:#32770]", "OK", 'Button2')
		Send('{ESC}')
	EndIf
EndFunc

Func Del_DB()
	For $i=0 To 5
		Send('{ESC}')
		Sleep (100)
	Next
	
	WinKill ( "[CLASS:Photo_Lightweight_Viewer]" )
	
	If ProcessExists ("PageViewer.exe") Then
		If ProcessExists ("PageViewer.exe") Then
			ProcessClose ( "PageViewer.exe")
			Sleep (500)
		EndIf
	EndIf	
	
	If ProcessExists ("Prestopm.exe") Then
		ProcessClose ( "Prestopm.exe")
		Sleep (1000)
	EndIf	
	
	If ProcessExists('Pmsb.exe') Then
		ProcessClose('Pmsb.exe')
	EndIf
	
	If ProcessExists('PMCloudShare.exe') Then
		ProcessClose('PMCloudShare.exe')
	EndIf
	
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd

	RefreshShellTrayToolbar()	

	Local $FileList
	$FileList = _FileListToArray($MY_PAGEMANAGER_FODLER_PATH, "*", 2)	
	If @error Then
	Else
		For $i = 1 To $FileList[0]
			If @error Then
			Else
				DirRemove($MY_PAGEMANAGER_FODLER_PATH & $FileList[$i], 1)
			EndIf
		Next
	EndIf
	FileDelete($MY_PAGEMANAGER_FODLER_PATH & "*.*")
	If ProcessExists("Prestopm.exe") Then
		ProcessClose("Prestopm.exe")
	EndIf	
	If ProcessExists("Pmsb.exe") Then
		ProcessClose("Pmsb.exe")
	EndIf
	If ProcessExists("PMSpeed.exe") Then
		ProcessClose("PMSpeed.exe")
	EndIf
	If ProcessExists("PageViewer.exe") Then
		ProcessClose("PageViewer.exe")
	EndIf
	DirRemove(Get_DB_Path(), 1)
	Run(PMSpeedEXE_Path())
	If @error Then Return False
EndFunc

Func Get_DB_Path()  
	If @OSVersion == 'WIN_XP' Then
		Return @UserProfileDir & '\Local Settings\Application Data\NewSoft\'
	Else	
		Return @UserProfileDir & '\AppData\Local\NewSoft\'
	EndIf
EndFunc	

Func Common_Run_PageManager($PMExePath)
	Local $Titile,$size
	Local $avArray[100]
	FileDelete(@MyDocumentsDir & "\My PageManager\*.*")
	Sleep(600)
	Local $PIDa = Run($PMExePath, "", @SW_MAXIMIZE)
	If @error Then Return ''
	Sleep(6000)
	If WinActivate("License") Then
		ControlClick("License", "", 1)
		Sleep(3000)
	EndIf
	If WinExists("[CLASS:#32770]", "Try") Then
		WinActivate("[CLASS:#32770]", "Try")
		ControlClick("[CLASS:#32770]", "Try", 1000)
		Sleep(10000)
	EndIf
	If WinExists("Scan Central") Then
		WinActivate("Scan Central")
		Sleep(500)
		WinClose("Scan Central")
	EndIf
	If ProcessExists ("PageViewer.exe") Then
		ProcessClose ( "PageViewer.exe")
		Sleep(500)
	EndIf
	Local $Var = WinList()
	For $i = 1 to $Var[0][0]
		If $Var[$i][0] <> "" And IsVisible($var[$i][1]) Then
			If Not @error Then
				$avArray[$i] = WinGetProcess($Var[$i][0])   ; Get all visible title PID.
				If Not @error Then
					If $PIDa = $avArray[$i] Then
						$Titile = $Var[$i][0]   ; Get PM title.
						$size = WinGetPos($Titile)   ;Get PM postion and size.
						MouseClick('left',($size[0] + $size[2] / 2), ($size[1])) 
						Sleep(1000)
						Return WinGetHandle($Titile)
					EndIf
				EndIf
			EndIf
		EndIf
	Next
EndFunc

Func Close_PM_EX($hHandle)
	For $i=0 To 5
		Send('{ESC}')
		Sleep (100)
	Next
	
	WinKill ( "[CLASS:Photo_Lightweight_Viewer]" )
	
	If ProcessExists ("PageViewer.exe") Then
		If ProcessExists ("PageViewer.exe") Then
			ProcessClose ( "PageViewer.exe")
			Sleep (500)
		EndIf
	EndIf	
	
	If ProcessExists ("Prestopm.exe") Then
		WinActivate($hHandle)   ;Activate the PM window.
		Sleep(500)
		Send ("!f")
		Sleep (500)
		Send ("E")   ; Close PM.
		Sleep (1000)
		If ProcessExists ("Prestopm.exe") Then
			ProcessClose ( "Prestopm.exe")
			Sleep (1000)
		EndIf
	EndIf	
	
	If ProcessExists('Pmsb.exe') Then
		ProcessClose('Pmsb.exe')
	EndIf
	
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd

	RefreshShellTrayToolbar()
EndFunc

Func RefreshShellTrayToolbar() 
	Local $hShell_TrayToolbar, $aShellTrayToolbarPos, $xShell_TrayToolbar, $yShell_TrayToolbar 
	Local $iMsg_WM_MOUSEMOVE   = 0x00000200 
	$hShell_TrayToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[CLASS:ToolbarWindow32; INSTANCE:1]") 
	$aShellTrayToolbarPos = ControlGetPos ("[Class:Shell_TrayWnd]", "", "[CLASS:ToolbarWindow32; INSTANCE:1]") 
	If IsArray($aShellTrayToolbarPos) Then 
		If $aShellTrayToolbarPos[2] >= 2 And $aShellTrayToolbarPos[3] >= 2 Then 
			$xShell_TrayToolbar = $aShellTrayToolbarPos[2] 
			$yShell_TrayToolbar = $aShellTrayToolbarPos[3] 
			For $i = 0 To $xShell_TrayToolbar - 1 Step 1 
				_SendMessage($hShell_TrayToolbar, $iMsg_WM_MOUSEMOVE, 0, Dec(Hex($yShell_TrayToolbar/2, 4)&Hex($i, 4) ), 0, "wparam", "lparam", "Int") 
			Next 
		EndIf 
	EndIf 
EndFunc 

Func SelectFileInThumbnail($iPostion)
	Switch $iPostion
	Case 0
		MouseClick('left',268, 166)
	Case 1
		MouseClick('left',420, 166)
	Case 2
		MouseClick('left',583, 167)
	Case 3
		MouseClick('left',741, 167)
	EndSwitch
	Sleep(2000)
EndFunc

Func SetSaveAsFileName_EX($sName)
	$id = 1152
	If ControlGetHandle('[CLASS:#32770]', 'FolderView', $id) == '' Then $id = 1148
	ControlFocus('[CLASS:#32770]', 'FolderView', $id)
	Sleep(3000)
	For $i = 0 To 20
		Send('{DEL}')
	Next
	For $i = 0 To 20
		Send('{BS}')
	Next	
	Sleep(1000)
	ControlFocus('[CLASS:#32770]', 'FolderView', $id)
	Sleep(500)
	Send($sName)
	;ControlSend('[CLASS:#32770]', 'FolderView', $id, $sName)
	Sleep(5000)
	ControlClick('[CLASS:#32770]', 'FolderView', "Button2")
	Sleep(8000)
	If WinExists("OCR") Then
		WinWaitClose("OCR", "", 30)
		Sleep(8000)
	EndIf
EndFunc

Func SmokingTest1_1_6_Image()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveAsdGlg() Then Return False
	SetSaveAsFormat_EX("JPEG(*.JPG)")	
	SetSaveAsFileName_EX($PERFORM_RESULT_FOLDER_PATH & '1.1.6_Save Image To Jpg')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_7_Image()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlg() Then Return False
	Sleep(3000)
	SaveXPS($PERFORM_RESULT_FOLDER_PATH & '1.1.7_Save Image To XPS')
	Close_PM_EX($hPMHandle)
EndFunc

Func SaveXPS($sName)
	ControlFocus('[CLASS:#32770]', 'FolderView', 1152)
	Sleep(1000)
	For $i = 0 To 20
		Send('{DEL}')
	Next
	For $i = 0 To 20
		Send('{BS}')
	Next	
	Sleep(1000)
	ControlSend('[CLASS:#32770]', 'FolderView', 1152, $sName)
	Sleep(5000)
	ControlClick('[CLASS:#32770]', 'FolderView', "Button2")
	Sleep(3000)
	Send('{ENTER}')
	Sleep(11000)
EndFunc

Func OpenSaveXPSDlg()
	Send('!f')
	Sleep(500)
	Send('j')
	If Not WinWait('[CLASS:#32770]', 'FolderView', 5) Then Return False
	WinActivate('[CLASS:#32770]', 'FolderView')
	Sleep(1000)
	Return True
EndFunc

Func SmokingTest1_1_6_MultiTif()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveAsdGlg() Then Return False
	SetSaveAsFormat_EX("JPEG(*.JPG)")	
	SetSaveAsFileName_EX($PERFORM_RESULT_FOLDER_PATH & '1.1.6_Save MultiTif To Jpg')
	Close_PM_EX($hPMHandle)
EndFunc

Func OpenSaveXPSDlgFromContextMenu()
	MouseClick('right',268, 166)	
	Sleep(1000)
	For $i = 0 to 3
		Send('{DOWN}')
		Sleep(200)
	Next
	Send('{RIGHT}')
	Sleep(1000)
	Send('{DOWN}')
	Sleep(500)
	Send('{ENTER}')
	Sleep(1000)
	#cs
	If Not WinWait('[CLASS:#32770]', 'Tree View', 5) Then Return False
	WinActivate('[CLASS:#32770]', 'Tree View')
	#ce
	Sleep(6000)
	Return True
EndFunc

Func SaveXPSContextMenu($sName)
	Sleep(3000)
	$id = 1001
	If ControlGetHandle('', '', $id) == '' Then $id = 1148
	ControlFocus('', '', $id)
	
	Sleep(1000)
	For $i = 0 To 20
		Send('{DEL}')
	Next
	For $i = 0 To 20
		Send('{BS}')
	Next	
	Sleep(1000)
	Send($sName)
	;ControlSend('', '', $id, $sName)
	Sleep(5000)
	;ControlClick('', '', "Button1")
	Send('{ENTER}')
	Sleep(11000)
EndFunc

Func SmokingTest1_1_8_Image()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.8_Print Image To XPS')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_8_MultiTif()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.8_Print MultiTif To XPS') 
	Close_PM_EX($hPMHandle)
EndFunc
	
Func SmokingTest1_1_8_PDF()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.8_Print PDF To XPS')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_8_Word()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.8_Print Word To XPS')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_7_MultiTif()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlg() Then Return False
	Sleep(3000)
	SaveXPS($PERFORM_RESULT_FOLDER_PATH & '1.1.7_Save MultiTif To XPS')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_6_PDF()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveAsdGlg() Then Return False
	SetSaveAsFormat_EX("JPEG(*.JPG)")	
	SetSaveAsFileName_EX($PERFORM_RESULT_FOLDER_PATH & '1.1.6_Save PDF To Jpg')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_7_PDF()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlg() Then Return False
	Sleep(3000)	
	SaveXPS($PERFORM_RESULT_FOLDER_PATH & '1.1.7_Save DPF To XPS')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_6_Word()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveAsdGlg() Then Return False
	SetSaveAsFormat_EX("JPEG(*.JPG)")	
	SetSaveAsFileName_EX($PERFORM_RESULT_FOLDER_PATH & '1.1.6_Save Word To Jpg')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_7_Word()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenSaveXPSDlg() Then Return False
	Sleep(3000)	
	SaveXPS($PERFORM_RESULT_FOLDER_PATH & '1.1.7_Save Word To XPS')
	Close_PM_EX($hPMHandle)
EndFunc

Func SetSaveAsFormat_EX($Format)
	ControlClick("[CLASS:#32770]", "FolderView", 1136)
	Sleep(500)
	Switch $Format   
	Case "BMP(*.BMP)"
		Send("b")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "JPEG(*.JPG)"
		Send("b")
		Sleep(200)		
		Send("j")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PaintBrush(*.PCX)"
		Send("b")
		Sleep(200)		
		Send("p")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-uncompressed(*.TIF)"
		Send("b")
		Sleep(200)	
		Send("t")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-packbits(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 1
			Send("t")
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-G3 compression(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 2
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-G4 compression(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 3
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-multiple page(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 4
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "JPEG(*.JPG)"
		Send("b")
		Sleep(200)	
		Send("j")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PICT(*.PCT)"
		Send("b")
		Sleep(200)	
		Send("p")
		Sleep(200)	
		Send("p")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Targa(*.TGA)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 5
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Targa-rle(*.TGA)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 6
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PNG(*.PNG)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 2
			Send("p")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Photoshop(*.PSD)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 3
			Send("p")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "GIF(*.GIF)"
		Send("b")
		Sleep(200)	
		Send("g")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Text(*.TXT)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 7
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Rich Text Format(*.RTF)"
		Send("b")
		Sleep(200)	
		Send("r")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "HTML(*.HTM)"
		Send("b")
		Sleep(200)	
		Send("h")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "XPS File(*.xps)"
		Send("b")
		Sleep(200)	
		Send("x")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)		
	EndSwitch
	Sleep(1000)		
	Return True
EndFunc

Func ClickSaveAs_PropertyBtn()
	If WinWait('[CLASS:#32770]', 'FolderView', 5) Then
		WinActivate('[CLASS:#32770]', 'FolderView')
		ControlClick('[CLASS:#32770]', 'FolderView', 1021)    
		If WinWait('Preferences', '', 5) Then
			WinActivate('Preferences')
			Sleep(500)
			Return True
		EndIf
	EndIf
	Return False
EndFunc

Func SetJPGMaxHighCompression()
	If WinWait('Preferences', '', 5) Then
		WinActivate('Preferences')
		For $i = 0 To 50
			Send('{LEFT}')
		Next
		Sleep(500)
		ControlClick('Preferences', '', 1)
		Sleep(500)
		Return True
	EndIf
	Return False	
EndFunc

Func OpenSaveAsdGlg()
	Send('^s')
	If Not WinWait('[CLASS:#32770]', 'FolderView', 5) Then Return False
	WinActivate('[CLASS:#32770]', 'FolderView')
	Sleep(1000)
	Return True
EndFunc

Func OpenPrintPDFDlgFromContextMenu()
	MouseClick('right',268, 166)	
	Sleep(1000)
	For $i = 0 to 3
		Send('{DOWN}')
		Sleep(200)
	Next
	Send('{RIGHT}')
	Sleep(1000)
	Send('{ENTER}')
	Sleep(1000)
	#cs
	If Not WinWait('[CLASS:#32770]', 'Tree View', 5) Then Return False
	WinActivate('[CLASS:#32770]', 'Tree View')
	#ce
	Sleep(6000)
	Return True
EndFunc

Func SmokingTest1_1_11_Image()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenPrintPDFDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.11_Print Image To PDF')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_11_MultiTif()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenPrintPDFDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.11_Print MultiTif To PDF')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_11_PDF()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenPrintPDFDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.11_Print PDF To PDF')
	Close_PM_EX($hPMHandle)
EndFunc

Func SmokingTest1_1_11_Word()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	If Not OpenPrintPDFDlgFromContextMenu() Then Return False
	Sleep(3000)
	SaveXPSContextMenu($PERFORM_RESULT_FOLDER_PATH & '1.1.11_Print Word To PDF')
	Close_PM_EX($hPMHandle)
EndFunc

Func SaveAsFromContextMenu()
	MouseClick('left',600, 400,2)
	Sleep(300)
	Send('!f')
	Sleep(500)
	Send('s')
	If Not WinWait('[CLASS:#32770]', 'FolderView', 5) Then Return False	
	Return True	
EndFunc

Func SmokingTest1_1_10()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '4_OCR_E.TIF', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	ControlClick($hPMHandle, '', 1012)   ;OCR button
	Sleep(20000)
	SaveAsFromContextMenu()
	Sleep(5000)
	SetSaveAsFormat_EX("Rich Text Format(*.RTF)")	
	SetSaveAsFileName_EX($PERFORM_RESULT_FOLDER_PATH & '1.1.10_Perform OCR Then Save To RTF')
	Sleep(4000)
	Close_PM_EX($hPMHandle)	
EndFunc

Func SmokingTest1_1_12($bIsHasPageviewer)
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '4_OCR_E.TIF', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	ControlClick($hPMHandle, '', 1002)   ;Find button
	Sleep(5000)
	ControlSetText('', '', 4002, '2_')  ;Set search contetent
	Sleep(500)
	ControlClick('', '', 4003)    ;Serch button
	Sleep(3000)
	ControlClick('', '', 4005)    ;Go to button
	If $bIsHasPageviewer Then
		Sleep(10000)
		_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & '1.1.12(This Image should is BizCard6.pdf).jpg', 203, 97, 1188, 905 , False)
	Else
		Sleep(20000)
		_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & '1.1.12(This Image should is BizCard6.pdf).jpg', 267, 107, 1009, 913, False)
	EndIf
	Close_PM_EX($hPMHandle)	
EndFunc

Func SmokingTest1_1_13()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '4_OCR_E.TIF', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	Send('^a')
	Sleep(5000)
	
	ControlClick($hPMHandle, '', 1009)   ;Stack button
	Sleep(5000)
	ControlClick($hPMHandle, '', 1025)   ;Unstack button
	Sleep(5000)	
	ControlClick($hPMHandle, '', 1009)   ;Stack button
	Sleep(5000)

	Send('^c')
	Sleep(2000)	
	Send('^v')
	Sleep(6000)
	
	WinActivate($hPMHandle)
	Send('{F5}')	
	Sleep(2000)
	
	MouseMove(1228, 813)
	Sleep(1000)
	
	_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & '1.1.13(This Image should has two group stack files).jpg', 200, 89, 1228, 813, False)
	
	Close_PM_EX($hPMHandle)	
EndFunc

Func GetTreeviewHandle($hPMHandle)
	Local $hTreeView = ControlGetHandle($hPMHandle, '', 'SysTreeView322')
	If $hTreeView == '' Then 
		Return ''
	Else
		Return $hTreeView
	EndIf	
EndFunc

Func SmokingTest1_1_13_()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	Send('^a')
	Sleep(5000)
	
	ControlClick($hPMHandle, '', 1009)   ;Stack button
	Sleep(5000)
	
    $hTreeView = GetTreeviewHandle($hPMHandle)
	If $hTreeView == '' Then Return False
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTreeView, 'My PageManager')
	_GUICtrlTreeView_SelectItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound)
	
	Send('!f')
	Sleep(1000)	
	Send('b')
	Sleep(6000)	
	ControlSetText('', '', 1010, '000_Backup_Folder')    ;backup folder name
	Sleep(500)	
	ControlSetText('', '', 1008,  @MDAY & @HOUR & @MIN & @SEC & @MSEC)    ;backup folder name
	Sleep(500)	
	ControlClick('', '', 1)    ;OK button
	Sleep(8000)	
	Send('{ENTER}')	
	Sleep(5000)	
#cs	   Restore
	MouseClick('left', 631, 461)
	WinActivate($hPMHandle)
	Sleep(500)	
    $hTreeView = GetTreeviewHandle($hPMHandle)
	If $hTreeView == '' Then Return False
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTreeView, 'My PageManager')	
	_GUICtrlTreeView_SelectItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound)
	Send('!f')
	Sleep(1000)	
	Send('r')
	Sleep(6000)	
	If ControlGetHandle('', '', 1014) == '' Then
		Send('{ENTER}')	
		Sleep(6000)	
	EndIf
	ControlClick('', '', 1014) 
	Sleep(6000)	
	ControlTreeView('','','SysTreeView321', 'Expand', "#0|#0")
	Sleep(2000)	
	ControlTreeView('','','SysTreeView321', 'Select', "#0|#0|#0")
	Sleep(2000)	
	ControlClick('', '', 1)    ;OK button
	Sleep(2000)	
	ControlClick('', '', 1)    ;OK button
	Sleep(8000)	
	
	Send('{ENTER}')	
	Sleep(5000)		
	_GUICtrlTreeView_SelectItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound)
	Send('{RIGHT}')
	Sleep(2000)	
	Send('{DOWN}')
	Sleep(5000)	
#ce
	_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & "1.1.13('000_Backup_Folder' is in tree view).jpg", 8, 87, 538, 826, False)
	
	Close_PM_EX($hPMHandle)	
EndFunc

Func SmokingTest1_1_14()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '4_OCR_E.TIF', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	
	For $i = 0 to 3 
		ControlClick($hPMHandle, '', 1006)  ;Zoom out
		Sleep(1000)
	Next
	
	MouseMove(1228, 813)
	Sleep(1000)
	_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & '1.1.14(All files should zoom out to min size).jpg', 196, 86, 1143, 904, False)
	
	For $i = 0 to 5
		ControlClick($hPMHandle, '', 1125)  ;Zoom out
		Sleep(1000)
	Next
	
	_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & '1.1.14(All files should zoom in to max size).jpg', 196, 86, 1143, 904, False)
	
	Close_PM_EX($hPMHandle)	
EndFunc

Func SmokingTest1_1_15()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	$hTreeView = GetTreeviewHandle($hPMHandle)
	If $hTreeView == '' Then Return False
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTreeView, 'My PageManager')
	_GUICtrlTreeView_SelectItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound)
	Sleep(2000)	
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound, 'right')
	Sleep(1000)
	Send('{DOWN}')
	Sleep(1000)
	Send('{ENTER}')
	Sleep(1000)
	Send('{ENTER}')
	Sleep(2000)
	_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & '1.1.15(New folder should created under My PageManage folder).jpg', 7, 223, 166, 863, False)
	Close_PM_EX($hPMHandle)	
EndFunc

Func SmokingTest1_1_17()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	Send('^a')
	Sleep(5000)
	
	ControlClick($hPMHandle, '', 1009)   ;Stack button
	Sleep(5000)
	
	SelectFileInThumbnail(0)
	Send('!f')
	Sleep(1000)
	Send('x')
	Sleep(1000)
	Send('{DOWN}')
	Sleep(1000)
	Send('{ENTER}')
	Sleep(5000)
	ControlSetText('','',1152,$PERFORM_RESULT_FOLDER_PATH & '1.1.17_Export_To_Wrapper')
	Sleep(1000)
	Send('{ENTER}')
	Sleep(4000)
	
	Close_PM_EX($hPMHandle)	
EndFunc

Func SmokingTest1_1_22()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	FileCopy($SAMPLE_FOLDER_PATH & '0_jpg.jpg', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '1_multi_tif.tif', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '2_pdf.pdf', $MY_PAGEMANAGER_FODLER_PATH, 1)
	FileCopy($SAMPLE_FOLDER_PATH & '3_word.doc', $MY_PAGEMANAGER_FODLER_PATH, 1)
	Sleep(5000)
	WinActivate($hPMHandle)
	Send('{F5}')
	WinActivate($hPMHandle)
	
	SelectFileInThumbnail(0)
	Send('^a')
	Sleep(5000)
	
	ControlClick($hPMHandle, '', 1009)   ;Stack button
	Sleep(5000)
	
	MouseClick('left', 1267, 947)   ;Document pallet button
	Sleep(2000)
	MouseClickDrag('left',263, 160,304, 879)
	Sleep(2000)
	MouseClick('left', 1224, 815)   ;Send button in Document pallet 
	Sleep(6000)
	
	_ScreenCapture_Capture($PERFORM_RESULT_FOLDER_PATH & "1.1.22(Show 'Copy of 3_word' stack files).jpg", 196, 86, 1143, 904, False)
	
	Close_PM_EX($hPMHandle)	
EndFunc

Func SmokingTest1_1_26()
	Del_DB()
	InitializeStatus()   
	$hPMHandle = LaunchAP(GetPMExePath())
	If $hPMHandle == '' Then Return False
	Sleep(3000)
	WinActivate($hPMHandle)
	Send('!h')
	For $i = 0 to 2
		Send('{DOWN}')
		Sleep(1000)
	Next
	Send('{ENTER}')
	Sleep(1000)
	If Not WinWait('NewSoft LiveUpdate Service') Then Return False
	Sleep(2000)
	ControlClick('NewSoft LiveUpdate Service', '', 1003)
	Sleep(5000)
	If Not WinWait("[CLASS:IEFrame]") Then Return False
	Sleep(22000)	
	WinSetState ("[CLASS:IEFrame]", "", @SW_MAXIMIZE)
	Sleep(3000)
	Local $h = ControlGetHandle(WinGetHandle("[CLASS:IEFrame]"), '', 'Internet Explorer_Server1')
	Local $iPos = GetWindowPostion($h)
	If @error Then Return False
	_ScreenCapture_CaptureWnd($PERFORM_RESULT_FOLDER_PATH & "1.1.26(Live Update).jpg", $h, 3, 3 ,$iPos[2] - 3,$iPos[3] - 3, False)		
	Sleep(1000)
	While ProcessExists("iexplore.exe")
		ProcessClose ("iexplore.exe")
	WEnd	
	Close_PM_EX($hPMHandle)	
EndFunc
